package org.abc.fund.controller.trade.response;

import lombok.Builder;
import lombok.Data;
import org.abc.fund.entity.trade.Settlement;
import org.abc.fund.entity.trade.TradeOrderDetail;

import java.math.BigDecimal;
import java.time.LocalDateTime;

@Data
@Builder
public class SettlementResponse {
  private Long id;
  private Long orderDetailId;
  private String fundCode;
  private String fundName;
  private TradeOrderDetail.Direction direction;
  private BigDecimal settledAmount;
  private BigDecimal settledShares;
  private BigDecimal fee;
  private LocalDateTime settledAt;

  public static SettlementResponse fromEntity(Settlement settlement) {
    TradeOrderDetail detail = settlement.getTradeOrderDetail();
    return SettlementResponse.builder()
        .id(settlement.getId())
        .orderDetailId(detail.getId())
        .fundCode(detail.getFund().getCode())
        .fundName(detail.getFund().getName())
        .direction(detail.getDirection())
        .settledAmount(settlement.getSettledAmount())
        .settledShares(settlement.getSettledShares())
        .fee(settlement.getFee())
        .settledAt(settlement.getSettledAt())
        .build();
  }
}
